//
//  JHHOtMOveTableViewCell.m
//  Liberty Voice
//
//  Created by dlios on 15-5-16.
//  Copyright (c) 2015年 ClearLove. All rights reserved.
//

#import "JHHOtMOveTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface JHHOtMOveTableViewCell ()

@property(nonatomic,retain)UIImageView *ablumBase;

@property(nonatomic,retain)UIImageView *ablumImage;
//@property(nonatomic,retain)UIButton *startButton;
@property(nonatomic,retain)UILabel *ablumTitle;

@property(nonatomic,retain)UIImageView *uSerImage;
@property(nonatomic,retain)UILabel *ablumUser;
@property(nonatomic,retain)UIImageView *playImage;
@property(nonatomic,retain)UILabel *ablumplay;
@property(nonatomic,retain)UIImageView *collectImage;
@property(nonatomic,retain)UILabel *ablumCollect;
@property(nonatomic,retain)UIImageView *commentImage;
@property(nonatomic,retain)UILabel *ablumComment;
@property(nonatomic,retain)UIImageView *durationImage;
@property(nonatomic,retain)UILabel *ablumDuration;
@end

@implementation JHHOtMOveTableViewCell
- (void)dealloc
{
    //    [_hotMusic release];
    [_ablumImage release];
    [_ablumCollect release];
    [_ablumComment release];
    [_ablumDuration release];
    [_ablumplay release];
    [_ablumTitle release];
    [_ablumUser release];
    [_collectImage release];
    [_commentImage release];
    [_playImage release];
    [_uSerImage release];
    [_durationImage release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //  底图
//        self.ablumBase = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_share_large"]] autorelease];
//        [self.contentView addSubview:_ablumBase];
        //  标题
        self.ablumTitle = [[[UILabel alloc] init]autorelease];
//        _ablumTitle.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_ablumTitle];
        //  头像
        self.ablumImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"]] autorelease];
        _ablumImage.layer.cornerRadius = 24.5;
        _ablumImage.layer.masksToBounds = YES;
        [self.contentView addSubview:_ablumImage];
        //        self.startButton = [UIButton buttonWithType:UIButtonTypeSystem];
        //        [_startButton setImage:[UIImage imageNamed:@"iconfont-play"] forState:UIControlStateNormal];
        //        [_hotMusicImage addSubview:_startButton];
        //  用户名
        self.uSerImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-my"]]autorelease];
        [self.contentView addSubview:_uSerImage];
        self.ablumUser = [[[UILabel alloc] init] autorelease];
        _ablumUser.font = [UIFont systemFontOfSize:14];
//        _ablumUser.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:_ablumUser];
        //  播放
        self.playImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-play"]] autorelease];
        [self.contentView addSubview:_playImage];
        self.ablumplay = [[[UILabel alloc] init] autorelease];
        _ablumplay.font = [UIFont systemFontOfSize:10];
//        _ablumplay.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_ablumplay];
        //  收藏
        self.collectImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-xiai"]]autorelease];
        [self.contentView addSubview:_collectImage];
        self.ablumCollect = [[[UILabel alloc] init] autorelease];
        _ablumCollect.font = [UIFont systemFontOfSize:10];
//        _ablumCollect.backgroundColor = [UIColor brownColor];
        [self.contentView addSubview:_ablumCollect];
        //  评论
        self.commentImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-mark"]] autorelease];
        [self.contentView addSubview:_commentImage];
        self.ablumComment = [[[UILabel alloc] init] autorelease];
        _ablumComment.font = [UIFont systemFontOfSize:10];
//        _ablumComment.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_ablumComment];
        //  时间
        self.durationImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-clock"]] autorelease];
        [self.contentView addSubview:_durationImage];
        self.ablumDuration = [[[UILabel alloc] init]autorelease];
        _ablumDuration.font = [UIFont systemFontOfSize:10];
//        _ablumComment.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_ablumDuration];
        
    }return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    _ablumImage.frame = CGRectMake(10, 10, self.contentView.frame.size.width / 5, self.contentView.frame.size.width / 5);
    //    _startButton.frame = CGRectMake(20, 20, _hotMusicImage.frame.size.width - 40, _hotMusicImage.frame.size.height - 40);
    
    CGFloat f = [[self class] heightWithText:_ablumTitle.text];
    _ablumTitle.frame = CGRectMake(_ablumImage.frame.size.width + 20, 10, self.contentView.frame.size.width - _ablumImage.frame.size.width - 20, f );
    
    _uSerImage.frame = CGRectMake(_ablumImage.frame.size.width + 20, _ablumTitle.frame.size.height+ 20, 20, 20);
    _ablumUser.frame = CGRectMake(_uSerImage.frame.origin.x + _uSerImage.frame.size.width + 10, _ablumTitle.frame.size.height + 20, 150, 20);
    _playImage.frame = CGRectMake(_ablumImage.frame.size.width + 20, _uSerImage.frame.origin.y + 30, 15, 15);
    _ablumplay.frame = CGRectMake(_playImage.frame.origin.x + 20, _uSerImage.frame.origin.y + 30, 35, 15);
    _collectImage.frame = CGRectMake(_ablumplay.frame.origin.x + 40, _uSerImage.frame.origin.y + 30, 15, 15);
    _ablumCollect.frame = CGRectMake(_collectImage.frame.origin.x + 20, _uSerImage.frame.origin.y + 30, 30, 15);
    _commentImage.frame = CGRectMake(_ablumCollect.frame.origin.x + 30, _uSerImage.frame.origin.y + 30, 15, 15);
    _ablumComment.frame = CGRectMake(_commentImage.frame.origin.x + 25, _uSerImage.frame.origin.y + 30, 35, 15);
    _durationImage.frame = CGRectMake(_ablumComment.frame.origin.x + 30, _uSerImage.frame.origin.y + 30, 15, 15);
    _ablumDuration.frame = CGRectMake(_durationImage.frame.origin.x + 20, _uSerImage.frame.origin.y + 30, 35, 15);
    
}
- (void)setHOTMOve:(JHHOTMOve *)HOTMOve
{
    if (HOTMOve != _HOTMOve) {
        [_HOTMOve release];
        _HOTMOve = [HOTMOve retain];
    }
    [_ablumImage sd_setImageWithURL:[NSURL URLWithString:HOTMOve.coverSmall]];
    _ablumTitle.text = HOTMOve.title;
    _ablumUser.text = HOTMOve.nickname;
//    _ablumplay.text = HOTMOve.playtimes;
//    _ablumCollect.text = HOTMOve.likes;
//    _ablumComment.text = HOTMOve.comments;
//    _ablumDuration.text = HOTMOve.duration;
    NSString *num = @"";
    if (HOTMOve.playtimes < 10000) {
        num = [NSString stringWithFormat:@"%ld",HOTMOve.playtimes];
    }else
        if (HOTMOve.playtimes > 10000) {
            //            NSInteger a = (recom.playsCounts / 10000.00);
            num = [NSString stringWithFormat:@"%.1f万",HOTMOve.playtimes / 10000.0];
        }
    
    _ablumplay.text = num;
    _ablumCollect.text = [HOTMOve.likes description];
    _ablumComment.text = [HOTMOve.comments description];
    NSString *miao = @"";
    if (HOTMOve.duration % 60 < 10) {
        miao = [NSString stringWithFormat:@"0%ld",HOTMOve.duration % 60];
    }else
        if (HOTMOve.duration % 60 >10) {
            miao = [NSString stringWithFormat:@"%ld",HOTMOve.duration % 60];
        }
    NSString *time = [NSString stringWithFormat:@"%ld:%@", HOTMOve.duration / 60 , miao];
    
    _ablumDuration.text = time;
}
+ (CGFloat)heightWithText:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};
    CGSize size = CGSizeMake(360, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
